package com.smsc.headend.task.engine.service.dds.impl;

import com.smsc.headend.common.constant.Constant;
import com.smsc.headend.module.data.entity.RdMeterReadsLp;
import com.smsc.headend.task.engine.manager.DdsFilterMdmDataManager;
import com.smsc.headend.task.engine.service.asset.AssetService;
import com.smsc.headend.task.engine.service.dds.DdsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class DdsServiceImpl implements DdsService {

    @Autowired
    DdsFilterMdmDataManager ddsFilterMdmDataManager;

    @Autowired
    AssetService assetService;

    @Override
    public void transformMeterReadResult(List<RdMeterReadsLp> rdMeterReadsLps) {
        String mdmFlag = assetService.getSystemProperty("SYNC_MDM_SWITCH");
        if (Constant.TRUE.equalsIgnoreCase(mdmFlag)) {
            ddsFilterMdmDataManager.transformMeterReadResultForMdm(rdMeterReadsLps);
        }
        //是否应生成CSV文件上传
        String flag = assetService.getSystemProperty("DDS_CSV_SWITCH");
        if (Constant.TRUE.equalsIgnoreCase(flag)) {
            ddsFilterMdmDataManager.transformMeterReadResultForMdmCsv(rdMeterReadsLps);
        }
        //是否应生成MultiSpeak文件上传
        String multiSpeakFlag = assetService.getSystemProperty("DDS_MULTISPEAK_SWITCH");
        if (Constant.TRUE.equalsIgnoreCase(multiSpeakFlag)) {
            String multiSpeakFileIsXml = assetService.getSystemProperty("DDS_MULTISPEAK_FILE_IS_XML");
            if (Constant.TRUE.equalsIgnoreCase(multiSpeakFileIsXml)) {
                ddsFilterMdmDataManager.transformMeterReadResultForOracleMdmXml(rdMeterReadsLps);
            } else {
                ddsFilterMdmDataManager.transformMeterReadResultForOracleMdmCsv(rdMeterReadsLps);
            }
        }
        //是否生成xml上传EIP
        String eipSwitch = assetService.getSystemProperty("DDS_EIP_SWITCH");
        if (Constant.TRUE.equalsIgnoreCase(eipSwitch)) {
            ddsFilterMdmDataManager.transformMeterReadResultForEIPXml(rdMeterReadsLps);
        }
    }
}
